<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Query Results</title>
	
	<script type="text/javascript" src="biojs/dependencies/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="biojs/dependencies/jquery/jquery-ui-1.8.2.custom.min.js"></script>
	<script type="text/javascript" src="biojs/dependencies/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="biojs/dependencies/jquery.multiselect.min.js"></script>
	<script type="text/javascript" src="biojs/dependencies/jmol-12.0.48/Jmol.js"></script>
    <script type="text/javascript" src="biojs/dependencies/graphics/raphael-2.1.0.js"></script>
	
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.Table.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.ResultsTable.js"></script>
    <script language="JavaScript" type="text/javascript" src="biojs/Biojs.Tooltip.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.TagCloud.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.Annotations.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.AnnotationsCloud.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.ChEBICompound.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.Tooltip.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.Protein3D.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.Protein3DWS.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.GeneExpressionSummary.js"></script>
	<script language="JavaScript" type="text/javascript" src="biojs/Biojs.Sequence.js"></script>
    <script language="JavaScript" type="text/javascript" src="biojs/Biojs.PDBLogos.js"></script>
    <script language="JavaScript" type="text/javascript" src="biojs/Biojs.ProteinPortafolio.js"></script>

    <link href="css/genesearch.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.Table.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.ResultsTable.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.TagCloud.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.AnnotationsCloud.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.ChEBICompound.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.Tooltip.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/biojs.GeneExpressionSummary.css" rel="stylesheet" type="text/css"/>
    <link href="biojs/css/biojs.Protein3D.css" rel="stylesheet" type="text/css"/>
	<link href="biojs/css/smoothness/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css"/>
    <link href="biojs/css/biojs.ProteinPortafolio.css" rel="stylesheet" type="text/css"/>
	

	
	<script language="JavaScript" type="text/javascript">//<![CDATA[
	    window.onload = function() {

            //Biojs.console.enable();

	        var myTable = new Biojs.ResultsTable({
				target: "list",
				dataSet: {
				    sparqlUrl: 'http://virtuoso.idiginfo.org/sparql',
					proxyUrl: 'biojs/dependencies/proxy/proxy.php',
				    filter: false
				},
				rowSelection: false,
				showColumnSelector: false,
                pageLength: 5
			});
			
			var myGeneExpression = new Biojs.GeneExpressionSummary({
      			target: 'geneExpressionSummary',
      			identifier: '',
      			collapsed: true
			});
			
			myTable.onCellClicked(function(e){
				myArticle.setData( myTable.getData(e.rowIndex) );
				showArticle();
			});
			
			jQuery('.back').click(function(){
				showResults();
			});
			
			// Gene expression
			myTable.onQueryRequest(function(e){
				myGeneExpression.setIdentifier(e.accession);
			});
			
			
			myTable.onDataArrived( function(e) {
		    	showResults();
			});

			Biojs.registerGlobal( 'resultsTable', myTable );
			
			
			if ( getUrlVars()["userQuery"] ) {
				doSearch(getUrlVars()["userQuery"]);
			} 

	    };
	    
	    function showResults(){

			if ( resultsTable.getTotalRecords() > 0 ) {
                var wiki = 'http://en.wikipedia.org/wiki/'+ escape(userQuery);
                jQuery('#wiki').html('<a target="_blank" class="link wiki" href="' + wiki + '">'+ wiki +'</a>').show();
	    		jQuery('#geneExpressionSummary').show();
	    		jQuery('#list').show();
	    		jQuery('#message').hide();
	    		
	    	} else {
	    		jQuery('#geneExpressionSummary').hide();
                jQuery('#wiki').hide();
	    		jQuery('#list').hide();
	    		jQuery('#message').html('No results using "' + userQuery + '" ').show();
	    	}
	    }

	    function doSearch( query ) {

            var userQuery = ( query == undefined )? jQuery('.searchbox .searchfield').val() : query;

            //if ( !Biojs.Utils.isEmpty(userQuery) ) {
            if ( userQuery != undefined && userQuery != ""  ) {
                jQuery('.searchbox .searchfield').val(userQuery);
                jQuery('#geneExpressionSummary').hide();
                jQuery('#list').hide();
                jQuery('#wiki').hide();
                jQuery('#message').html('Searching...').show();
                Biojs.registerGlobal( 'userQuery', userQuery );
                resultsTable.setQuery( userQuery );
            }

            return false;

	    } 
	    
	    function getUrlVars() {
    		var vars = {};
		    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		        vars[key] = value;
		    });
		    return vars;
		}

	    function showGraph () {
	    	var userQuery = jQuery('.searchbox .searchfield').val();
	    	
	    	if ( userQuery != undefined && userQuery != "" && userQuery != "Search..."  ) {
	    		window.location.href = "graph.html" + "?userQuery="+userQuery;
	    	} else {
	    		window.location.href = "graph.html";
	    	}
	    }

	     //]]>
	</script>

</head>
<body>
	<div id="header" class="grid12 first">
		<div class="grid6 first searchbox">
			<span>Gene search</span>
			<form class="searchform" onsubmit="doSearch();" action="#">
				<input class="searchfield" type="text" value="Search..." onfocus="if (this.value == 'Search...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search...';}">
				<input class="searchbutton" type="button" value="Go" onclick="doSearch();">
			</form>
	        <span> Examples: <a onclick="doSearch('catalase');" style="cursor: pointer;">catalase</a>, <a onclick="doSearch('insulin');" style="cursor: pointer;">insulin</a></span>
		</div>
		<div class="grid3 toolbar"><img src="css/images/group.png" title="Go to graph view" onclick="showGraph();" /></div>
	</div>

	<div class="grid12 clearfix first">

        <div id="wiki" style="display:none; padding-bottom: 10px;" class="grid4 first"></div>
		<div id="geneExpressionSummary" style="display:none;" class="grid12 first page-curl shadow-bottom"></div>
		<div id="list" class="grid12 first"></div>
		<div id="message" style="display:none;" class="grid12"></div>
	
	</div>
	
</body>
</html>